package com.learning.demos.jvmgc;

import com.sun.tools.attach.VirtualMachine;
import sun.misc.VM;

import java.nio.ByteBuffer;

/**
 * @author adolphw
 * 使用jvm堆内存外的物理内存
 * -Xms10m -Xmx10m -XX:+PrintGCDetails -XX:MaxDirectMemorySize=5m
 *
 * Exception in thread "main" java.lang.OutOfMemoryError: Direct buffer memory
 */
public class OOMDirectBuffMemoryDemo {

    public static void main(String[] args) {
        System.out.println("maxDirectMemory:" + VM.maxDirectMemory() / 1024 / 1024 + "MB");


        ByteBuffer byteBuffer = ByteBuffer.allocateDirect(6 * 1024 * 1024);
    }
}
